function loginInit()
{
	if (top.location != self.location)
	{
        top.location=self.location;
    }
	
	$('.loginbox').css({'position':'absolute','left':($(window).width()-692)/2});
	$(window).resize(function(){  
    	$('.loginbox').css({'position':'absolute','left':($(window).width()-692)/2});
	});
	
	$(document).keydown(function(event){
		if(event.keyCode == 13)
		{
			Login_Submit();
		}
	});
}	

// 提交登录请求
function Login_Submit()
{
	var url = projectName+"/login/login.do?date=" + new Date().getTime();
	$.ajax({
		url : url,
		async : false,
		data:{"name":$("#name").val(),"password":$("#password").val(),"code":$("#code").val()},
		success : function(data,result)
		{
			if("SUCCESS" == data)
			{
				// 跳转到首页
				window.location.href = projectName+"/jsp/main/main.jsp";
			}
			else if ("FREEZE" == data)
			{
				loginMessageAlert(3,"用户被冻结，请联系管理员",function(){
					this.close();
					window.location.href = projectName+"/jsp/login.jsp";
				});
			}
			else if("ERROR" == data)
			{
				loginMessageAlert(3,"用户名或密码错误",function(){
					this.close();
					window.location.href = projectName+"/jsp/login.jsp";
				});
			}
			else if("CODEWARONG" == data)
			{
				loginMessageAlert(3,"验证码错误",function(){
					this.close();
					window.location.href = projectName+"/jsp/login.jsp";
				});
			}
			else if("CODENULL" == data)
			{
				loginMessageAlert(3,"请输入验证码",function(){
					this.close();
				});
			}
			else
			{
				loginMessageAlert(3,"登录异常，请重试",function(){
					this.close();
					window.location.href = projectName+"/jsp/login.jsp";
				});
			}
		},
		error:function(XMLHttpRequest, textStatus, errorThrown)
		{
			alert(XMLHttpRequest.status);
			 alert(XMLHttpRequest.readyState);
			 alert(textStatus);
		}
	});
}

/**
 * 验证码点击事件  
 */
function changeCodeImg()
{
	var imgSrc = $("#imgCode");
    var src = projectName + "/login/getCode.do?date=" + new Date().getTime();
    imgSrc.attr("src", src);
}

/**
 * 登录页面弹框
 */
function loginMessageAlert(type,info,functionOk,functionNo)
{
	var iconInfo = "";
	switch(type)
	{
	     case 0: iconInfo='info';break;
	     case 1: iconInfo='success';break;
		 case 2: iconInfo='warning';break;
		 case 3: iconInfo='error';break;
		 case 4: iconInfo='question';break;
		 default: return;
	}
	// 自定义提示弹框
	BUI.Message.Show({
		msg : info,
		icon : iconInfo,
		buttons : [
			{
				text:'确定',
				elCls : 'button button-primary',
				handler : functionOk
		    }
		]
	});
}
